package com.briup.estore.mapper;

import java.math.BigInteger;
import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import com.briup.estore.bean.Category;

@Mapper
public interface ICategoryMapper {

	@Select("select a.id c1_id,a.name c1_name,a.description c1_description,b.id c2_id,b.name c2_name,b.description c2_description,b.category_id c2_category_id, "
			+ "c.id book_id,c.name book_name,c.price book_price,c.author book_author,c.publisher book_publisher,c.pubdate book_pubdate, "
			+ "c.description book_description,c.category_id book_category,c.images book_images ,c.click book_click from ES_CATEGORY a ,ES_CATEGORY b , ES_BOOK c "
			+ "where a.id = b.category_id and c.category_id = b.id  ")
	@ResultMap("com.briup.estore.mapper.ICategoryMapper.categoriesResultMap")
	List<Category> findAllCategoryWithBooks();

	@Select("select a.id c1_id,a.name c1_name,a.description c1_description,b.id c2_id,b.name c2_name,b.description c2_description,b.category_id c2_category_id "
			+ "from ES_CATEGORY a ,ES_CATEGORY b " + "where a.id = b.category_id")
	@ResultMap("com.briup.estore.mapper.ICategoryMapper.categoriesResultMap")
	List<Category> findAllCategories();

	@Select("select * from es_category ")
	List<Category> selectCategories();

	@Select("select b.id book_id,b.name book_name,b.price book_price,b.author book_author,"
			+ "b.publisher book_publisher,b.pubdate book_pubdate,b.description book_description,"
			+ "b.category_id book_category_id,b.images book_images,b.click book_click,"
			+ "C2.id c2_id,C2.name c2_name,C2.description c2_description " + "from es_book b right join es_category c2 "
			+ "on b.CATEGORY_ID = c2.id " + "where C2.CATEGORY_ID is not null and C2.id = #{id}")
	@ResultMap("com.briup.estore.mapper.ICategoryMapper.categoryResultMap")
	Category findCategoryWithBooksById(BigInteger id);

	@Select("select C1.id c1_id,C1.name c1_name,c1.description c1_description,C2.id c2_id,"
			+ "c2.name c2_name,C2.description c2_description,C2.CATEGORY_ID c2_category_id"
			+ " from ES_CATEGORY c2 LEFT JOIN ES_CATEGORY c1 on C2.CATEGORY_ID = C1.id where  C2.id = #{id} ")
	@ResultMap("com.briup.estore.mapper.ICategoryMapper.categoryResultMap3")
	Category findCategoryWithCategoryById(BigInteger id);
}
